package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Role;
import com.woniuxy.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：jojo
 * @Date：2022/3/8 14:45
 * @Description :TODO
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired(required = false)
    RoleService roleService;
    @ApiOperation(value = "添加角色")
    @RequestMapping("/add")
    public ResponseEntity addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }
    @ApiOperation(value = "删除某个角色")
    @RequestMapping("/delet/{id}")
    public ResponseEntity delet(@PathVariable int id){
        return roleService.delet(id);
    }
    @ApiOperation(value = "修改某个角色")
    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody Role role){
        System.out.println(role.toString());
        return roleService.update(role);
    }
    @ApiOperation(value = "查询所有角色")
    @RequestMapping("/findAll")
    public ResponseEntity findAll(){
        return roleService.findAll();
    }

    @ApiOperation(value = "给某个角色添加某个权限")
    @RequestMapping("/addPerm/{permid}/{roleid}")
    public ResponseEntity addPerm(@PathVariable("permid") int permid,@PathVariable("roleid") int roleid){
        return roleService.addPerm(permid,roleid);
    }

    @ApiOperation(value = "查用户权限")
    @RequestMapping("/findUserRole/{id}")
    public ResponseEntity findUserRole(@PathVariable("id") int id){
        return roleService.findUserRole(id);
    }

    @ApiOperation(value = "查所有角色")
    @RequestMapping("/findrole/{id}")
    public ResponseEntity findRole(@PathVariable("id") int id){
        return roleService.findRole(id);
    }

}
